import React, { Component } from 'react'
export default class reducer01 extends Component {
    state = { num: 0 }
    redur = (type, argnum) => {
        let { num } = this.state;
        switch (type) {
            case "add":
                num += argnum;
                break;
            case "sup":
                num -= argnum;
                break;
            default:
                break;
        }
        this.setState({ num })
    }
    render() {
        const { num } = this.state
        return (
            <div>
                {num} <br />
                <button onClick={()=>{this.redur('add',2)}}>相加2</button>
                <button onClick={()=>{this.redur('sup',2)}}>相减2</button>
                <button onClick={()=>{this.redur('*',2)}}>保持不变</button>
            </div>
        )
    }
}
